function onEventStart()
	if getElementType ( source ) == "player" then
		local account = getPlayerAccount ( source )
		if account and not isGuestAccount ( account ) then
			if getAccountData ( account, "memeFace" ) then
				setElementData ( source, "memeLogged", true )
				setElementData ( source, "memeRender", getAccountData ( account, "memeRender" ) )
				setElementData ( source, "memeFace", getAccountData ( account, "memeFace" ) )
				setElementData ( source, "memeColor", getAccountData ( account, "memeColor" ) )
			end
		else
			setElementData ( source, "memeLogged", false )
		end
	else
		for k,v in ipairs ( getElementsByType ( "player" ) ) do
			local account = getPlayerAccount ( v )
			if account and not isGuestAccount ( account ) then
				if getAccountData ( account, "memeFace" ) then
					setElementData ( v, "memeLogged", true )
					setElementData ( v, "memeRender", getAccountData ( account, "memeRender" ) )
					setElementData ( v, "memeFace", getAccountData ( account, "memeFace" ) )
					setElementData ( v, "memeColor", getAccountData ( account, "memeColor" ) )
				end
			else
				setElementData ( v, "memeLogged", false )
			end
		end
	end
end

function memeSave ( render, face, color )
	local account = getPlayerAccount ( source )
	if account then
		setAccountData ( account, "memeRender", render )
		setAccountData ( account, "memeFace", face )
		setAccountData ( account, "memeColor", color )
	end
	setElementData ( source, "memeRender", render )
	setElementData ( source, "memeFace", face )
	setElementData ( source, "memeColor", color )
	triggerClientEvent ( "memeSaved", source )
	outputChatBox ( "Meme Saved!", source )
end

addEvent ( "memeSave", true )
addEventHandler ( "memeSave", root, memeSave )
addEventHandler ( "onResourceStart", resourceRoot, onEventStart )
addEventHandler ( "onPlayerLogin", root, onEventStart )
addEventHandler ( "onPlayerLogin", root, function() triggerClientEvent ( "onClientPlayerLogin", source ) end )
addEventHandler ( "onPlayerLogout", root, function() triggerClientEvent ( "onClientPlayerLogout", source ) end )